#define  _CRT_SECURE_NO_WARNINGS 1
#include "game.h"
//函数的实现
void InitBoard(char board[Row][Clo], int row, int clo)//初始化棋盘-初始化空格
{
	for (int i = 0; i < row; i++)
	{
		for (int j = 0; j < clo; j++) {
			board[i][j] = ' ';
		}
	}
}
void DisplayBoard(char board[Row][Clo], int row, int clo)//打印棋盘—本质上是打印数组的内容
{

	for (int i = 0; i < row; i++)//行
	{
		for (int j = 0; j < clo; j++) {
			printf(" %c ", board[i][j]);
			if (j < clo - 1)
			{
				printf("|");
			}
		}
		printf("\n");
		if (i < row - 1)
		{
			for (int j = 0; j < clo; j++)//列
			{
				printf("---");
				if (j < clo - 1)
				{
					printf("|");
				}
			}
			printf("\n");
		}
	}

}
void PlayMove(char board[Row][Clo], int row, int clo)//玩家玩
{
	int x = 0;
	int y = 0;
	printf("请玩家下棋:\n");
	while (1)
	{
		printf("请输入下棋的坐标\n");
		scanf("%d %d", &x, &y);
		if (x >= 1 && x <= row && y >= 1 && y <= clo)//判断坐标是否合法
		{
			if (board[x - 1][y - 1] == ' ')//判断坐标是否被占用
			{
				board[x - 1][y - 1] = '*';
				break;//只有输入正确的坐标才能跳出循环
			}
			else
			{
				printf("坐标被占用,请重新输入\n");
			}
		}
		else
		{
			printf("坐标非法，请重新输入：\n");
		}
	}
}
void ComputerMove(char board[Row][Clo], int row, int clo)//电脑下
{
	printf("电脑走：\n");
	while (1)
	{
		int x = rand() % 3;//0 1 2 不用判断坐标是否合法
		int y = rand() % 3;
		if (board[x][y] == ' ')//判断是否占用
		{
			board[x][y] = '#';
			break;
		}
	}
}
int IsFull(char board[Row][Clo], int row, int clo)
{
	for (int i = 0; i < row; i++)
	{
		for (int j = 0; j < clo; j++)
		{
			if (board[i][j] == ' ')
			{
				return 0;
			}
		}
	}
	return 1;
}